2010/02/23

[Note] Setup subversion server with Apache2, and e-mail hook

Have done this for several times recently, so I put down a note for it. On a Snow Leopard server, extra tools may be required, here is a reference.



  1. Install subversion. On a Debian-family Linux box, simply type:

    $ sudo apt-get install subversion


  2. Find a place to put the repository, for example, /usr/local/myrepo. Create your repository by typing:

    $ sudo svnadmin create /usr/local/myrepo



  3. Setup remote connection with Apache2 and WebDAV.

    1. Make sure you have apache2 installed and DAV module enabled (reference).

    2. Edit the configuration file. For example, /etc/apache2/sites/0000_xxxxx.conf

    3. Add the following code section somewhere before the </VirtualHost> tag.

      <Location "/myrepo_http">
      DAV svn
      AuthName "giftalk"
      SVNPath /usr/local/myrepo
      AuthType Basic
      AuthUserFile /usr/local/myrepo/myrepo.pw
      Order deny,allow
      <Limit GET HEAD OPTIONS CONNECT POST PROPFIND PUT DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
      Require valid-user
      </Limit>
      </Location>

    4. To restart the apache2 server:

      $ apachectl restart




  4. Add authentication mechanism with htpasswd. In the previous step we specify an file for authentication with AuthUserFile /usr/local/myrepo/myrepo.pw. To create an user account to access this repository, do:

    $ htpasswd -c /usr/local/myrepo/myrepo.pw myaccount

    And then input a password twice for the user myaccount. The option -c is used to create this file (assume it doesn't exist), and add an user named myaccount. To add more accounts or to change the password, just skip this -c option.


  5. Add e-mail hook
    This step requires either a perl or a python script, depending on your system.

    1. Go to the hooks folder in the repository, say, /usr/local/myrepo/hooks. There are many scripts with affix .tmpl within. Do:

      $ cp post-commit.tmpl post-commit


    2. Assume the system use python scripts, mailer.py. Find the script and corresponding configuration file mailer.conf from the apache2 installation, or from internet. Copy these two files into /usr/local/myrepo/hooks/, and make sure their are executable.

    3. Edit the /usr/local/myrepo/hooks/post-commit, at the end of the file, add the mailing mechanism:

      /usr/local/myrepo/hooks/mailer.py commit "$REPOS" "$REVS" /usr/local/myrepo/hooks/mailer.conf


    4. In the mailer.conf, add the e-mail address to receive the updates at the line:

      to_addr = myemail@my.email.server






Now, this repository should be able to work properly. More on access control, please see here.

沒有留言: